class PostsController < ApplicationController
  skip_before_filter :require_login,except: [:create,:new]

  def index
    @posts = Post.order(:created_at).page params[:page]
  end
  def show
    @post = Post.find( params[:id] )
    @post.visited_count+=1
    @post.save()
  end
  def new
    @post = Post.new
  end
  def create
    @post = Post.new(post_params)
    @post.user_id = current_user.id
    if @post.save()
      flash[:success] = "分享文章成功"
      redirect_to posts_path
    end
  end

  private

  def post_params
    params.require(:post).permit(:title,:content)
  end
end
